<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>购物车</title>
</head>
<body>
    <input type="checkbox" name="shoes" id="shoes">篮球鞋
    <input type="checkbox" name="jsbook" id="jsbook">《你不知道的JavaScript》
    <input type="submit" onclick="calculation()">
    <script>

/*
* @func 计算购物车的总价
* @return (int)
*/
      function calculation(){
        let sum=0;
                // 对象字面量 鞋子
         const goods=[];
        goods[0] ={
            name : '篮球鞋',
            color :'白黑',
            store:'束制旗舰店',
            price: 138,
            size: 41,
            isselect:document.getElementById('shoes').checked
        }
        //对象字面量 js图书
        goods[1] ={
            name: '你不知道的javaScript',
            store: '出版集团图书专营店',
            price: 49.3,
            coupon:5,  //优惠券
            isselect:document.getElementById('jsbook').checked
        }
        
        function total(goods){
           if(goods.price)
             sum+=goods.price;
           if(goods.coupon)
             sum-=goods.coupon;
        }
        for(let i=0;i<goods.length;i++){
            if(goods[i].isselect)
            {  
               total(goods[i]);
               console.log(goods[i].name+"+1 ");
            }
        }
        console.log("合计：￥"+sum);
    }
    </script>
</body>
</html>